home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWDELSTA_H
- #define FWDELSTA_H
-
- //========================================================================================
- //
- // File: FWDelSta.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FW_NATIVE_EXCEPTIONS
-
- #ifndef FWEXCTAS_H
- #include "FWExcTas.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWEXCRUN_H
- #include "FWExcRun.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- class FW_CLASS_ATTR FW_CPrivDeleteStack;
- class FW_CLASS_ATTR FW_CPrivDeleteEntry;
- class FW_CLASS_ATTR _FW_CAutoDestructObject;
-
- //========================================================================================
- // CLASS FW_CPrivDeleteEntry
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CPrivDeleteEntry
- {
- public:
-
- enum __DeleteType
- {
- __kObject,
- __kGuard,
- __kDeleted,
- __kInvalid
- };
-
- __DeleteType fType;
- union
- {
- _FW_CAutoDestructObject * fObject;
- FW_ClassInfoPtr fGuard;
- };
-
- void *fObjectVTable; // The objects v table at time of construction
-
- FW_CPrivDeleteEntry(_FW_CAutoDestructObject * anObject);
- FW_CPrivDeleteEntry(FW_ClassInfoPtr guard);
-
- __DeleteType GetType();
- void SetType(__DeleteType type);
- FW_ClassInfoPtr GetGuard();
- _FW_CAutoDestructObject *GetObject();
- };
-
-
- //========================================================================================
- // CLASS FW_CPrivDeleteStack
- //
- // The delete stack is maintained as an array of pointers to DeleteEntry, and three
- // pointers into the array. The three pointers are the StackBase, StackTop, and
- // StackLimit. The StackBase points to the beginning of the array, the StackLimit points
- // one past the last position in the array, and the StackTop points one past the last
- // pushed item. When the stack is empty, StackBase == StackTop. When the stack is
- // full StackTop == StackLimit. If an item is pushed when the stack is full, it is
- // resized, which may move the array, so all three pointers need to be updated. To do
- // this, an integer offset RelativeTopOfStack is sometimes used to remember the location
- // of a StackTop across code that might resize the stack.
- //
- // Class Invariants:
- // GetStackBase() != NULL
- // GetStackBase() <= GetStackTop() <= GetStackLimit()
- // GetStackTop() == GetStackBase() + RelativeTopOfStack()
- // GetStackBase() + GetCurrentStackSize() == GetStackLimit()
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CPrivDeleteStack
- {
- public:
- static void Initialize(FW_SPrivExceptionGlobals& globals);
- static void Terminate();
-
- static inline void Push(_FW_CAutoDestructObject* anObject);
- static inline void Push(FW_ClassInfoPtr aGuard);
-
- static int IsClassExpectedInContext(FW_CPrivTryBlockContext *context, FW_ClassInfoPtr thrownType);
- // Search for a guard that would prevent throwing this class to the next context.
- // If we don't find such a guard then return true otherwise return false.
-
- static void PopOffAndDeleteObjectsInContext(FW_SPrivExceptionGlobals& globals,
- FW_CPrivTryBlockContext *context);
- static _FW_StackEntries RelativeTopOfStack(FW_SPrivExceptionGlobals& globals);
- static void PopIfTopEquals(_FW_CAutoDestructObject* anObject);
- static FW_ClassInfoPtr PopGuard();
-
- private:
- static void Push(void * aGuardOrObject, FW_CPrivDeleteEntry::__DeleteType deleteType);
-
- enum
- {
- kNumberOfObjectsToGrowStack = 256,
- kStepByteSize = kNumberOfObjectsToGrowStack * sizeof(FW_CPrivDeleteEntry)
- };
-
- static void SetStackTop(FW_SPrivExceptionGlobals& globals, FW_CPrivDeleteEntry * pStackTop);
-
- #ifdef FW_DEBUG
- static void CheckClassInvariants(FW_SPrivExceptionGlobals& globals);
- #endif
- };
-
- //========================================================================================
- // STRUCT FW_CPrivThrowGuard
- //========================================================================================
-
- struct FW_CLASS_ATTR FW_CPrivThrowGuard
- {
- #ifdef FW_DEBUG
- FW_ClassInfoPtr fGuardClass;
- #endif
- FW_CPrivThrowGuard();
- FW_CPrivThrowGuard(FW_ClassInfoPtr guard);
- ~FW_CPrivThrowGuard();
- };
-
- //========================================================================================
- // CLASS FW_CPrivDeleteEntry INLINE Functions
- //========================================================================================
-
- inline FW_CPrivDeleteEntry::__DeleteType FW_CPrivDeleteEntry::GetType()
- {
- return fType;
- }
-
- inline void FW_CPrivDeleteEntry::SetType(__DeleteType type)
- {
- fType = type;
- }
-
- inline FW_ClassInfoPtr FW_CPrivDeleteEntry::GetGuard()
- {
- FW_PRIV_ASSERT(fType == __kGuard);
- return fGuard;
- }
-
- inline _FW_CAutoDestructObject *FW_CPrivDeleteEntry::GetObject()
- {
- FW_PRIV_ASSERT(fType == __kObject);
- return fObject;
- }
-
- //========================================================================================
- // CLASS FW_CPrivDeleteStack INLINE Functions
- //========================================================================================
-
- inline void FW_CPrivDeleteStack::SetStackTop(FW_SPrivExceptionGlobals& globals,
- FW_CPrivDeleteEntry* pStackTop)
- {
- #ifdef FW_DEBUG
- pStackTop->SetType(FW_CPrivDeleteEntry::__kInvalid);
- #endif
- globals.gStackTop = pStackTop;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivDeleteStack::RelativeTopOfStack
- //----------------------------------------------------------------------------------------
- inline _FW_StackEntries FW_CPrivDeleteStack::RelativeTopOfStack(FW_SPrivExceptionGlobals& globals)
- {
- return globals.gStackTop - globals.gStackBase;
- }
-
- //========================================================================================
- // CLASS FW_CPrivDeleteStack INLINE Functions (Platform independent versions)
- //========================================================================================
-
- inline void FW_CPrivDeleteStack::Push(FW_ClassInfoPtr aGuard)
- {
- Push((void*) aGuard, FW_CPrivDeleteEntry::__kGuard);
- }
-
- inline void FW_CPrivDeleteStack::Push(_FW_CAutoDestructObject* anObject)
- {
- Push((void*) anObject, FW_CPrivDeleteEntry::__kObject);
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif // FW_NATIVE_EXCEPTIONS
-
- #endif
-